<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>年龄</title>
</head>
<body id="bodyid">
    <input type="button" id="btn" value="请输入您出生年份:">
    <div> 
        <p>你的年龄为:<input type="text" id="y"></p>
    </div>
    
</body>
<script type="text/javascript">
    document.getElementById("btn").onclick=function(){
        var year = prompt("请输入你的出生年份：")
    year=parseFloat(year) && Number(year);
    if (!isNaN(year)) {
        var y=2019-year;
        document.getElementById("y").value=y;
    }else{
        alert('请输入正确的数字!')
 
    }
    }
</script>
<html>
